eval(loadFile("main/src/viz.js"));

var window;
var graphics;
var slides;
var frameRate;
var control;

testCases(test,
    function setUp() {
        window = {
            setInterval : function (toRepeat, timeDelay) {
                this.interval = {
                    toRepeat : toRepeat,
                    timeDelay : timeDelay
                };
                return this.interval;
            },
            clearTimeout : function (interval) {
                if (this.interval === interval) {
                    this.interval = {};
                }
            }
        };
        graphics = {};
        slides = {
            init : function (graphics) {}
        };
        frameRate = 15;
        control = viz(graphics).control(slides, frameRate);
    },

    function shouldMoveSlidesNext() {
        slides.nextSlide = assert.functionThatMustBeCalled("nextSlide");
        control.next();
    },

    function shouldMoveSlidesPrevious() {
        slides.previousSlide = assert.functionThatMustBeCalled("previousSlide");
        control.previous();
    },

    function shouldInitialiseSlidesWhenPlayed() {
        slides.init = assert.functionThatMustBeCalled("init", function (initialisedWith) {
            assert.that(initialisedWith, eq(graphics));
        });
        control.play();
    },

    function shouldStopReinitialiseSlidesWhenDoublyPlayedWithoutStopping() {
        control.play();
        slides.init = assert.functionThatMustNotBeCalled("init");
        control.play();
    },

    function shouldRepeatedlyProjectThenMoveToNextFrameOfSlidesWhenPlayed() {
        control.play();
        assert.that(window.interval.timeDelay , eq(Math.floor(1000 / frameRate)));

        slides.project = assert.functionThatMustBeCalled("project", function (projectedVia) {
            assert.that(projectedVia, eq(graphics));
        });
        slides.nextFrame = assert.functionThatMustBeCalled("nextFrame");
        window.interval.toRepeat();
    },

    function shouldStopMultipleProjectionsWhenDoublyPlayedWithoutStopping() {
        control.play();
        var existingInterval = window.interval;
        control.play();
        assert.that(window.interval , eq(existingInterval));
    },

    function shouldRemoveProjectionWhenStopped() {
        control.play();
        control.stop();
        var notDefined;
        assert.that(window.interval.toRepeat , eq(notDefined));
    }
);